/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app.WeightedFPTree;

/**
 *
 * @author Kumori
 */
public class CofiTree {
    public class CofiTreeNode{
        short  item;
        int  counter;
        CofiTreeNode[] children = null;
        CofiTreeNode[] siblings = null;
        CofiTreeNode parent = null;
        //CofiTreeNode nodeLink = null;
        public CofiTreeNode(short itemName){
            item = itemName;
        }
        public CofiTreeNode (short itemName, CofiTreeNode parentNode){
            parent = parentNode;
            
        }
    }
    
    public CofiTreeNode rootNode;
    public CofiTreeNode[] supportSets = null;     
    public CofiTree(short itemName){
        rootNode = new CofiTreeNode(itemName);
    };
    public FPtree rootTree;
    
    public CofiTreeNode[]  rellocInsert(CofiTreeNode[] oldItemSet, CofiTreeNode newElement){
        
        if (oldItemSet == null){
            CofiTreeNode[] newItemSet = {newElement};
            return newItemSet;
        }
        CofiTreeNode[] newItemSet = new CofiTreeNode[oldItemSet.length+1];
        for (int i = 0; i<oldItemSet.length; i++){
            newItemSet[i] = oldItemSet[i];
        }
        newItemSet[oldItemSet.length] = newElement;
        return newItemSet;
    };   
    
    public void createCofiTree(){
        System.out.println("Creating "+ rootNode.item +" COFITree");
        
    };
    public void miningCofiTree(){
        System.out.println("Miningting "+ rootNode.item +" COFITree");
    };
    
    
/*    private boolean addToCofitree1(FPtreeNode ref, int place, short[] itemSet,
    			int support, FPgrowthHeaderTable[] headerRef) {	
			
	// Loop	
	if (ref.childRefs != null) {
	    for (int index=0;index<ref.childRefs.length;index++) {
	        // If item is already in list of child refs
	        // increment count and proceed down branch.
	        if (itemSet[place] == ref.childRefs[index].node.itemName) {
	            ref.childRefs[index].node.itemCount =
		                 ref.childRefs[index].node.itemCount + support;
		    numUpdates++;
		    addToFPtree(ref.childRefs[index],place+1,itemSet,support,
		    		headerRef);
		    return(true);
		    }
	        // Child refs ordered lexicographically so break when passed
		// point where item should be
		if (itemSet[place] < ref.childRefs[index].node.itemName) 
					return(false);
		}
	    }	
        
	// Default
	
	return(false);
	}

    /* ADD TO FP TREE 2 */
    
    /** Adds new node to FP-tree. <P> Adds first attribute in itemSet and then 
    rest of sequence. 
    @param ref the current FP-tree node reference.
    @param place the current index in the given itemset.
    @param itemSet the given itemset.
    @param support the associated support value for the given itemset.
    @param headerRef the link to the appropriate place in the header table. */
    
 /*   private void addToCofitree2(FPtreeNode ref, int place, short[] itemSet,
    				int support, FPgrowthHeaderTable[] headerRef) {	
	
	// Create new Item Prefix Subtree Node
	FPgrowthItemPrefixSubtreeNode newPrefixNode = new 
	    		FPgrowthItemPrefixSubtreeNode(itemSet[place],support,ref.node);
	// Create new FP tree node incorporating new Item Prefix Subtree Node
	FPtreeNode newFPtreeNode = new FPtreeNode(newPrefixNode);
	// Add link from header table
	addRefToFPgrowthHeaderTable(itemSet[place],newPrefixNode,headerRef);
	// Add into FP tree
	ref.childRefs = reallocFPtreeChildRefs(ref.childRefs,newFPtreeNode);
	// Proceed down branch with rest of itemSet
	addRestOfitemSet(ref.childRefs[tempIndex],newPrefixNode,place+1,itemSet,
				support,headerRef);
	}*/
 }
